export function setCookie (key, value, seconds, path = '/') {
  var date = new Date()
  // 减8小时得到世界标准事件
  date.setTime(date.getTime() - 8 * 3600 * 1000 + seconds * 1000)
  document.cookie = `${key}=${value};expires=${path}`
}

export function getCookie (key) {
  // 所有cookie =>  ' key=value; key=value; ....'
  var cookies = document.cookie
  if (!cookies) return
  var arr = cookies.split('; ')
  for (var a = 0; a < arr.length; a++) {
    var brr = arr[a].split('=')
    if (brr[0] === key) {
      return brr[1]
    }
  }
}

export function removeCookie (key, path = '/') {
  // 修改有效时间使其过期失效
  setCookie(key, null, -1, path)
}
